package jmine.tec.database.query.columns;

import java.io.IOException;
import java.sql.Clob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import jmine.tec.utils.io.IOUtils;

/**
 * Coluna que trata de campos CLOB
 * 
 * @author lundberg
 */
public class ClobColumn extends AbstractColumn {

    /**
     * Construtor
     * 
     * @param type type
     * @param name name
     */
    public ClobColumn(int type, String name) {
        super(type, name);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String read(ResultSet rs) {
        try {
            Clob value = rs.getClob(this.getName());
            return value == null ? "null" : IOUtils.readFullyClose(value.getCharacterStream());
        } catch (SQLException e) {
            return super.read(rs);
        } catch (IOException e) {
            return super.read(rs);
        }
    }

    /**
     * {@inheritDoc}
     */
    public void setParameter(PreparedStatement st, int parameterIndex, String value) throws SQLException {
        throw new UnsupportedOperationException("Filtro por campo CLOB não suportado.");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean supportsFilters() {
        return false;
    }
}
